home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- # make-sizes
- # copyleft (c) 2000, joseph cheek, joseph@cheek.com. released under MIT.
- #
- # make-sizes:
- # create the file $BUILDROOT/col/data/sizes
- # $1 = RPMDIR
- # $2 = sizes file
- #
- # ex: ./make-sizes ../../../../col24_gold/col/install/RPMS/ ../sizes
- #
- # uses rpmshow, cut, printf
- #
- # this file is a list of directories and sizes included with each of the
- # RPM packages included in a build. It is used by lisa [and lizard?],
- # probably to figure out if there is enough disk space for the packages
- # you wish to install.
- #
- # each time an RPM is rebuilt, this file needs to be rebuilt. in
- # practice it should be rebuilt for each build IMHO.
-
- # BUG: if the rpm lists files in dir1, then files in dir2, then files in
- # dir1 again, we don't aggregate the file sizes in dir1; instead dir1 gets
- # two totals, one for each set of files listed.
-
- # BUG: this assumes 1K block sizes, and doesn't count space for directory
- # entries. this follows Caldera's behavior.
-
- # extract the data for each RPM
-
- TMPFILE=/tmp/`basename $0`.$$
-
- ( cd "$1"
-
- # process each RPM file in a for loop
- # Caldera's file doesn't have an exact order for packages
- # ours is in ASCII order by package filename
- # this behavior matches Caldera's ~95%
- for a in *
- do
-
- # first show the name of the RPM
- RPM_NAME=`rpmextr --tag=name $a`
- echo "[$RPM_NAME]"
- DIR_NAME=""
- DIR_SIZE=0
-
- # get file info for each RPM
- # don't want pre or post scripts
- # rpmshow $a 2> /dev/null| ( while read b
- rpmextr --cpio $a | cpio -itv 2> /dev/null| ( while read b
- do
-
- b=`echo "$b"`
-
- case "$b"
- in
-
- # only count regular files; all of these we can ignore
- --empty-- | %pre* | %post* | l* | d* | b* | c* | p* )
- continue
- ;;
-
- -r* | --* )
- # these are the files to count. round up to nearest 1K block and then
- # add to count. check to be sure the directory here is the right one.
-
- #first, get rounded up file size
- FILE_SIZE=`echo $b | cut -d \ -f 5`
- FILE_SIZE=$[ ($FILE_SIZE + 1023) / 1024 * 1024 ]
-
- # then get dir name; keep only first three paths tho
- FILE_DIR_NAME=/`echo $b | cut -d \ -f 9`
- # Caldera's script adds trailing / if dirname is less than three pathnames
- # they would put /usr/sbin/ where we put /usr/sbin
- # [cut 1-4 this time because of leading /]
- FILE_DIR_NAME=`dirname $FILE_DIR_NAME | cut -d / -f 1-4`
-
- if [ "$FILE_DIR_NAME" != "$DIR_NAME" ]
- then # new dir, output info on last dir
- if [ "$DIR_SIZE" -gt 0 ]
- then
- printf "%-32s %s\\n" "$DIR_NAME" "$DIR_SIZE"
- fi
-
- DIR_SIZE=0
- DIR_NAME="$FILE_DIR_NAME"
- fi
-
- DIR_SIZE=$[ $DIR_SIZE + $FILE_SIZE ]
- ;;
-
- *)
- echo -e unknown in $RPM_NAME: $b\\a >&2
- ;;
-
- esac
-
- done # get file info for each RPM
-
- # output info on last dir
- if [ "$DIR_SIZE" -gt 0 ]
- then
- printf "%-32s %s\\n" "$DIR_NAME" "$DIR_SIZE"
- fi
-
- ) > "$TMPFILE"
- # sort differs from Caldera's version; their's seems to be in no
- # particular order
- sort "$TMPFILE"
-
- done # process each RPM file in a for loop
-
- ) > "$2"
-
- rm "$TMPFILE"
-